//
//  AppDelegate+Config.m
//  ccZone
//
//  Created by 陈小娟 on 2017/12/6.
//  Copyright © 2017年 CC. All rights reserved.
//

#import "AppDelegate+Config.h"
#import "CCRootController.h"
#import <AFNetworking.h>
#import "CCLoginNetWorkTool.h"

@implementation AppDelegate (Config)

-(void)initRoot{
    [self configAppearance];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(logout) name:CCLogoutNotice object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(loginSuccess) name:CCLoginSuccessNotice object:nil];
    [[CCLoginNetWorkTool shareLoginNetworkTool] login];//测试自动登陆

    //监控网络的变化
    AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
    
    //不同的网络环境下，可以设置网络请求的最大并发数
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:{
                NSLog(@"未知");
            } break;
            case AFNetworkReachabilityStatusNotReachable:{
                NSLog(@"没有网络");
            }break;
            case AFNetworkReachabilityStatusReachableViaWiFi:{
                NSLog(@"3G/4G");
            } break;
            case AFNetworkReachabilityStatusReachableViaWWAN:{
                NSLog(@"WIFI");
            } break;
            default:
                break;
        }
    }];
    
    [manager startMonitoring];
}

-(void)loginSuccess {
    self.window.rootViewController = [CCRootController shareTabTootController];
}

-(void)logout {
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
    self.window.rootViewController = sb.instantiateInitialViewController;
}

- (void)configAppearance
{
    UINavigationBar * navBar = [UINavigationBar appearance];
    navBar.barStyle = UIBarStyleBlack;
    [navBar setTintColor:[UIColor darkTextColor]];//nav两侧字体+系统返回的剪头颜色颜色
    [navBar setBarTintColor:TY_NAV];//nav背景景色
    [navBar setTitleTextAttributes: @{NSForegroundColorAttributeName:TY_RGB(34,28,28, 1)}];//nav标题颜色
    
    UITabBar * tabBar = [UITabBar appearance];
    [tabBar setTintColor:TY_NAV];//tabBarItem点中颜色
    if (@available(iOS 10.0, *)) {
        [tabBar setUnselectedItemTintColor:TY_RGB(162,162,162,1)];
    } else {
        // Fallback on earlier versions
    }
    [tabBar setBarTintColor:TY_RGB(255.0, 255.0, 255.0, 1.0)];//tabBar背景色色
}

@end
